package com.luoxiang.socialandroid.extensions

import android.view.View
import android.view.inputmethod.EditorInfo
import android.widget.EditText

/**
 * Author: Sakura

 * Date: 2023/4/19

 * Description:
 */

/**
 * 将键盘的回车键设置为进行搜索,并返回点击回调
 *
 * @param operate 回调
 * @receiver
 */
fun EditText.enterActionListener(operate: (text: String?) -> Unit) {
    setOnEditorActionListener { v, actionId, event ->
        if (actionId == EditorInfo.IME_ACTION_SEARCH) {
            operate.invoke(text.toString())
        }
        false
    }
}